#include "EditorNodePositionPropertyViewModel.h"

#include "Window/EditorWindowGroupModel.h"
#include "Window/EditorMainWindowModel.h"
#include "Pages/EditorPageModel.h"

#include "Scene/SceneNode.h"

void REditorNodePositionPropertyViewModel::BindModel(TSharedObjectPtr<REditorPropertyModel> InModel
        ,TSharedObjectPtr<REditorObjectPropertyAbilityViewModel> InAbilityViewModel)
{
    Super::BindModel(InModel,InAbilityViewModel);
    NodePositionModel = InModel;
}

float REditorNodePositionPropertyViewModel::GetX() const
{
    return NodePositionModel->GetX();
}

void REditorNodePositionPropertyViewModel::SetX(float InX)
{
    auto Page=REditorWindowGroupModel::Get()->GetFocusedPage();
    auto Opearation = NewObject<REditorNodePositionPropertyOperation>(Page);
    Opearation->Objects.Add(NodePositionModel->Node);
    Opearation->ChangeValue(
        NodePositionModel->Node
        ,REditorNodePositionPropertyOperation::EAxis::X
        ,NodePositionModel->GetX()
        ,InX);

    Page->AddAndRedoOperation(Opearation);
}

float REditorNodePositionPropertyViewModel::GetY() const
{
    return NodePositionModel->GetY();
}

void REditorNodePositionPropertyViewModel::SetY(float InY)
{
    auto Page=REditorWindowGroupModel::Get()->GetFocusedPage();
    auto Opearation = NewObject<REditorNodePositionPropertyOperation>(Page);
    Opearation->Objects.Add(NodePositionModel->Node);
    Opearation->ChangeValue(
        NodePositionModel->Node
        ,REditorNodePositionPropertyOperation::EAxis::Y
        ,NodePositionModel->GetY()
        ,InY);

    Page->AddAndRedoOperation(Opearation);
}

float REditorNodePositionPropertyViewModel::GetZ() const
{
    return NodePositionModel->GetZ();
}

void REditorNodePositionPropertyViewModel::SetZ(float InZ)
{
    auto Page=REditorWindowGroupModel::Get()->GetFocusedPage();
    auto Opearation = NewObject<REditorNodePositionPropertyOperation>(Page);
    Opearation->Objects.Add(NodePositionModel->Node);
    Opearation->ChangeValue(
        NodePositionModel->Node
        ,REditorNodePositionPropertyOperation::EAxis::Z
        ,NodePositionModel->GetZ()
        ,InZ);

    Page->AddAndRedoOperation(Opearation);
}
